'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.genCallbackMap = undefined;

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var count = 0;
var genCallbackMap = exports.genCallbackMap = function genCallbackMap() {
    var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
        _ref$idPrefix = _ref.idPrefix,
        idPrefix = _ref$idPrefix === undefined ? 'genCallbackMap_' : _ref$idPrefix;

    var cbMap = {};
    var add = function add(fn, opts) {
        count++;
        var id = idPrefix + count;
        cbMap[id] = (0, _extends3.default)({
            fn: fn
        }, opts);
        return id;
    };
    var get = function get(id) {
        return cbMap[id];
    };
    var remove = function remove(id) {
        return delete cbMap[id];
    };
    var getFn = function getFn(id) {
        var cb = cbMap[id];
        return cb && cb.fn;
    };
    return {
        add: add,
        remove: remove,
        get: get,
        getFn: getFn
    };
};
exports.default = genCallbackMap;